package com.demo.config;

import com.demo.commons.BaseConsts;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import feign.Request;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Component
public class TokenFilter implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        String token=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
                .getHeader(BaseConsts.TOKEN_KEY);
        if (token!=null){
            requestTemplate.header(BaseConsts.TOKEN_KEY,token);
        }
    }
}
